import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Scanner;

import Controllers.GlobalData;
import Controllers.GenericToolsForController.BaseClass;
import Controllers.GenericToolsForController.RequestMainStatusEnum;
import Controllers.GenericToolsForController.RequestStepStatusEnum;
import Entity.Request;
import Entity.RequestStatusHistory;
import Entity.Status;
import Entity.User;
import Entity.Worker;
import fit.ActionFixture;

/**
 * 
 */


public class AskForMoreTime extends ActionFixture
{
	
	int evaluatorId;
	int requestId;
	String reason;
	int additionalTime;
	
	ArrayList<Request> requestsList;
	private static String LocalNetworkConfigurtaion = "ConfigServerOption.txt";
	
	public AskForMoreTime()
	{
		
	}
	 
	//Connect to the Server.
	public void enterToSystem()
	{
		
		Request req;
		requestsList = new ArrayList<Request>();
		
		Worker evaluator_62,evaluator_2;   // can be examiner/chairman etc. specifically we want to check about EVL step 
		evaluator_62 = new Worker(1, 62, "shimon", "Arzuan", "icmbraudesys@gmail.com", "0508-1234567", "shimon1171", "2" );
		evaluator_2 = new Worker(2, 2, "guy", "peleg", "icmbraudesys@gmail.com", "0508-1234567", "guyp", "2" );
		User initiator = new User(3, "Ron", "Rosesnfeld","icmbraudesys@gmail.com", "0508-1234567", "roon", "Student");		

		//the current worker that log to the system
		GlobalData.worker = evaluator_62;
		
		//======= More than 3 days till due time ============================================================		
		req = new Request();
		req.setRequestId(21);
		req.setEvaluator(evaluator_62);
		
		req.setInitiator(initiator);
		Status status = new Status(RequestStepStatusEnum.EVL_UNVALUATED_WITH_TIME, RequestMainStatusEnum.OPEN); 
	
		Date sDate = new Date(); 
		Date dDate;
		Calendar cal = Calendar.getInstance();  
		cal.setTime(sDate);  
		cal.add(Calendar.DATE, 5); // add 5 days   
		dDate = cal.getTime(); 
		
		RequestStatusHistory cureentStatus = new RequestStatusHistory(1, status, sDate , dDate , null, null, null);
		req.setCurrentStatus(cureentStatus);
		ArrayList<RequestStatusHistory> history = new ArrayList<RequestStatusHistory>();
		history.add(cureentStatus);
		req.setHistory(history);
		
		requestsList.add(req);

		
		//======== Less than 3 days till due time ===========================================================
		req = new Request();
		req.setRequestId(22);
		req.setEvaluator(evaluator_62);
		req.setInitiator(initiator);
		status = new Status(RequestStepStatusEnum.EVL_UNVALUATED_WITH_TIME, RequestMainStatusEnum.OPEN); 
		
		cal = Calendar.getInstance();  
		cal.setTime(sDate);  
		cal.add(Calendar.DATE, 2); // add 2 days   
		dDate = cal.getTime(); 
		
		cureentStatus = new RequestStatusHistory(2, status, sDate , dDate , null, null, null);
		req.setCurrentStatus(cureentStatus);
		history = new ArrayList<RequestStatusHistory>();
		history.add(cureentStatus);
		req.setHistory(history);
		requestsList.add(req);
		
		
		//======== Less than 3 days till due time and have got time extension in this step already ==============
		
		req = new Request();
		req.setRequestId(23);
		req.setEvaluator(evaluator_62);
		req.setInitiator(initiator);
		status = new Status(RequestStepStatusEnum.EVL_EVLUATION_EXTENDED, RequestMainStatusEnum.OPEN); 
		
		cal = Calendar.getInstance();  
		cal.setTime(sDate);  
		cal.add(Calendar.DATE, 2); // add 2 days   
		dDate = cal.getTime();
		
		cureentStatus = new RequestStatusHistory(3, status,  sDate , dDate , null, null, null);
		req.setCurrentStatus(cureentStatus);
		history = new ArrayList<RequestStatusHistory>();
		history.add(cureentStatus);
		req.setHistory(history);
		requestsList.add(req);
		
		
		// ======== Less than 3 days till due time and mStatus of request is SUSPEND ==============
		
		
		req = new Request();
		req.setRequestId(24);
		req.setEvaluator(evaluator_62);
		req.setInitiator(initiator);
		status = new Status(RequestStepStatusEnum.EVL_UNVALUATED_WITH_TIME, RequestMainStatusEnum.SUSPEND); 
		
		cal = Calendar.getInstance();  
		cal.setTime(sDate);  
		cal.add(Calendar.DATE, 2); // add 2 days   
		dDate = cal.getTime();
		
		cureentStatus = new RequestStatusHistory(4, status, sDate , dDate , null, null, null);
		req.setCurrentStatus(cureentStatus);
		requestsList.add(req);		
		
		
		// =========================== request in TST_PASSED sStatus ===============================
		
		req = new Request();
		req.setRequestId(25);
		req.setEvaluator(evaluator_62);
		req.setInitiator(initiator);
		status = new Status(RequestStepStatusEnum.TST_PASSED, RequestMainStatusEnum.OPEN); 
		cureentStatus = new RequestStatusHistory(4, status, new Date(), new Date(), null, null, null);
		req.setCurrentStatus(cureentStatus);
		history = new ArrayList<RequestStatusHistory>();
		history.add(cureentStatus);
		req.setHistory(history);
		requestsList.add(req);
		
		
		// ============ request in EVL_EVLUATION_TIME_EXTENSION_PENDING sStatus waits for approval ===============
		
		
		req = new Request();
		req.setRequestId(26);
		req.setEvaluator(evaluator_62);
		req.setInitiator(initiator);
		status = new Status(RequestStepStatusEnum.EVL_EVLUATION_TIME_EXTENSION_PENDING, RequestMainStatusEnum.OPEN); 
		cureentStatus = new RequestStatusHistory(4, status, new Date(), new Date(), null, null, null);
		req.setCurrentStatus(cureentStatus);
		history = new ArrayList<RequestStatusHistory>();
		history.add(cureentStatus);
		req.setHistory(history);
		requestsList.add(req);
		
		
		
		// ============ request in EVL_EVLUATION_EXTENDED_DENY sStatus time extension was denied ===============
		
		req = new Request();
		req.setRequestId(27);
		req.setEvaluator(evaluator_62);
		req.setInitiator(initiator);
		status = new Status(RequestStepStatusEnum.EVL_EVLUATION_EXTENDED_DENY, RequestMainStatusEnum.OPEN); 
		cureentStatus = new RequestStatusHistory(4, status, new Date(), new Date(), null, null, null);
		req.setCurrentStatus(cureentStatus);
		history = new ArrayList<RequestStatusHistory>();
		history.add(cureentStatus);
		req.setHistory(history);
		requestsList.add(req);

		
		
		// ==== request in EVL_UNVALUATED_WITH_TIME sStatus , 2 days till due date, and didn't got any time extension ===============
	
	/*	req = new Request();
		req.setRequestId(28);
		req.setEvaluator(evaluator_62);
		req.setInitiator(initiator);
		
		status = new Status(RequestStepStatusEnum.EVL_UNVALUATED_WITH_TIME, RequestMainStatusEnum.OPEN); 
		
		cal = Calendar.getInstance();  
		cal.setTime(sDate);  
		cal.add(Calendar.DATE, 2); // add 2 days   
		dDate = cal.getTime();
		
		cureentStatus = new RequestStatusHistory(4, status, sDate , dDate , null, null, null);
		req.setCurrentStatus(cureentStatus);
		history = new ArrayList<RequestStatusHistory>();
		history.add(cureentStatus);
		req.setHistory(history);
		requestsList.add(req);*/
	
		
		// ==== request in EVL_UNVALUATED_WITH_TIME sStatus , less than 3 days to due date, didn't got any time extension ===============
		
		
		GlobalData.worker = evaluator_62;
		
		req = new Request();
		req.setRequestId(29);
		req.setEvaluator(evaluator_2);
		req.setInitiator(initiator);
		status = new Status(RequestStepStatusEnum.EVL_UNVALUATED_WITH_TIME, RequestMainStatusEnum.OPEN); 
		
		cal = Calendar.getInstance();  
		cal.setTime(sDate);  
		cal.add(Calendar.DATE, 2); // add 2 days   
		dDate = cal.getTime();
		
		cureentStatus = new RequestStatusHistory(4, status,  sDate , dDate, null, null, null);
		req.setCurrentStatus(cureentStatus);
		history = new ArrayList<RequestStatusHistory>();
		history.add(cureentStatus);
		req.setHistory(history);
		requestsList.add(req);

	}
	public void requestNumber(int number)
	{
		this.requestId = number;
	}
	
	public void evaluatorId(int number)
	{
		this.evaluatorId = number;
	}
	
	public void reason(String str)
	{
		this.reason = str;
	}
	
	public void additionalTime(int days)
	{
		this.additionalTime = days;
	}
	
	
	public boolean askForMoreTime()
	{
		for(Request req : requestsList)
		{
			
			
			if(req.getRequestId() == requestId)
					return req.ackForMoreTime(this.additionalTime,this.reason, 0);   
		}
			
			return false;
	}
		
}
